package com.example.module_mine.ui

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.example.module_mine.R

@Route(path = "/module_mine/MyapplyActivity")
class MyapplyActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_myapply)
        val recyclerView = findViewById<RecyclerView>(R.id.recycler_view)
        recyclerView.layoutManager = LinearLayoutManager(this)
        recyclerView.adapter = ApplicationHistoryAdapter(getSampleData())
    }

    private fun getSampleData(): List<ApplicationHistoryItem> {
        return listOf(
            ApplicationHistoryItem("车位申请", "申请地下停车场 B2-108 车位", "2023-12-28 14:30", "待审批"),
            ApplicationHistoryItem("来访申请", "访客：陈明远（3人）| 来访时间：2023-12-27", "2023-12-26 09:15", "已通过"),
            ApplicationHistoryItem("报修申请", "办公室空调维修（A栋 1203）", "2023-12-25 16:45", "已拒绝"),
            ApplicationHistoryItem("巡更申请", "B区域夜间巡更路线调整申请", "2023-12-24 11:20", "已通过")
        )
    }

    data class ApplicationHistoryItem(val type: String, val content: String, val date: String, val status: String)

    class ApplicationHistoryAdapter(private val items: List<ApplicationHistoryItem>) : RecyclerView.Adapter<ApplicationHistoryAdapter.ViewHolder>() {

        override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
            val view = LayoutInflater.from(parent.context).inflate(R.layout.item_application_history, parent, false)
            return ViewHolder(view)
        }

        override fun onBindViewHolder(holder: ViewHolder, position: Int) {
            val item = items[position]
            holder.type.text = item.type
            holder.content.text = item.content
            holder.date.text = item.date
            holder.status.text = item.status
            when (item.status) {
                "待审批" -> holder.status.setTextColor(0xFFF44336.toInt())
                "已通过" -> holder.status.setTextColor(0xFF4CAF50.toInt())
                "已拒绝" -> holder.status.setTextColor(0xFF2196F3.toInt())
            }

        }

        override fun getItemCount() = items.size

        inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
            val type: TextView = itemView.findViewById(R.id.text_type)
            val content: TextView = itemView.findViewById(R.id.text_content)
            val date: TextView = itemView.findViewById(R.id.text_date)
            val status: TextView = itemView.findViewById(R.id.text_status)
        }
    }
}